<?php
$ma_nganh=$_GET['ma_nganh'];
$ma_donvi=$_GET['donvi'];
$namkhoahoc=$_GET['namkhoahoc'];
include('../../configs/connect.php');   
 mysql_query("SET NAMES 'UTF8'");
 
    $sql="  SELECT  ma_lop,ten_lop 
            From    tbl_donvi_ctdt,tbl_ctdt,tbl_khoahoc,tbl_lop
            WHERE   tbl_donvi_ctdt.ma_ctdt=tbl_ctdt.ma_ctdt
            AND     tbl_donvi_ctdt.id_dv_ctdt=tbl_khoahoc.id_dv_ctdt
            AND     tbl_khoahoc.id_khoahoc=tbl_lop.id_khoahoc
            AND     tbl_lop.ma_donvi='$ma_donvi'
            AND     nam_khoahoc='$namkhoahoc' ";
    $ma_nganh=rtrim($ma_nganh,','); 
    $mang=explode(',',$ma_nganh);
    $mang_nganh="";         
    for($i=0;$i<count($mang);$i++){
        $mang_nganh.="'".$mang[$i]."',";
    }         
    
    $mang_nganh=rtrim($mang_nganh,',');
    $sql=$sql." AND madm_nganh IN (".$mang_nganh.")";

$q=mysql_query($sql);
echo mysql_error();
$myarray=array();
$str="";
while($nt=mysql_fetch_array($q)){
$str=$str ."\"$nt[ma_lop]\"".","."\"$nt[ten_lop]\"".",";
}
$str=substr($str,0,(strLen($str)-1)); // Removing the last char , from the string
echo "new Array($str)";

?>